#ifndef GAME_H
#define GAME_H

#include <QWidget>
#include <QStackedLayout>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QLabel>
#include <QSerialPort>
#include <QCheckBox>
#include "widget.h"

namespace Ui {
class game;
}

class game : public QWidget
{
    Q_OBJECT

public:
    explicit game(QWidget *parent = nullptr,QSerialPort *serialPort = nullptr,Widget *parentWidgetPtr = nullptr);
    ~game();

    QGraphicsDropShadowEffect *shadowSet(bool choice);

    QWidget *getGameWidget();

    void dateInit(QDateTime *nowTime);

    int getQuestionId(int rowCount);

    void showQuestion(int id);

    bool isRepeat(int randomCount,uint8_t model,uint8_t (*usdedID)[2],uint8_t picCount);//判断是否重复，model：0 训练 1：购物清单获取 2：是否有重复显示

    int dbRowCount(bool model);//model：0 训练 1：情景

    void buttonClick();

    void SenceCliked();

    void dailyClick();

    void meatClick();

    void fruiltClick();

    void packClick();

    void exitButtonClick();

    void getShopList(int rowCount);

    void clearPic();

    void clearShopList();

    void showPic(QString zoon);

    QString extractBorderImage(const QString& styleSheet);//查看border image

    void checkPicClick(QCheckBox *pic);//按下pic时触发的事件,检查当前选中的是否在购物清单上


signals:
    void sendEmit();
    void sendOver();//游戏结束
    void sceneEmit();//情景开始
    void sceneOver();

public slots:
    void on_button_clicked();


private slots:

    void on_choiceA_clicked();

    void on_choiceB_clicked();

    void on_choiceC_clicked();

    void gameStart();

    void on_pushButton_clicked();//训练开始按钮

    void on_button_2_clicked();

    void gameOver();

    void onNewData(); // 当 Widget 发出 newDataAvailable 时触发

    void sceneStart();//情景开始初始化

    void sceneFinish();//情景结束

    void on_dailyButton_clicked();

    void on_meatButton_clicked();

    void on_fruiltButton_clicked();

    void on_packButton_clicked();

    void on_pic1_clicked();

    void on_pic2_clicked();

    void on_pic3_clicked();

    void on_pic4_clicked();

    void on_exitButton_clicked();

    void on_button_3_clicked();

private:
    Ui::game *ui;
    QStackedLayout* gameLayout;
    uint8_t gameMode = 0;
    //训练成员
    uint8_t questionID[10] = {0};
    uint8_t answeredID[10] = {0};
    uint8_t count;
    uint8_t gameRowCount;
    QSerialPort *gameSerial;
    Widget *parentWidget;
    bool processingEnabled = false; // 控制是否启用数据处理
    //情景成员
    uint8_t ListID[4] = {0};
    uint8_t selectID[4] = {0};
    uint8_t listCount = 0;
    uint8_t shoppedCount = 0;
};

#endif // GAME_H
